//
//  MsgUserFileCell.swift
//  swiftim
//
//  Created by yangjian on 2023/6/13.
//

import Foundation

class MsgUserFileCell : MsgUserBaseCell {
    
    let fileIconView = UIImageView()
    let fileNameLabel = UILabel()
    let fileSizeLabel = UILabel()
    
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.configMsgSubViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configMsgSubViews() {
        configBubbleView(superView: msgBackgroundView, aboveView: msgContentView)

        msgContentView.addSubview(fileIconView)
        msgContentView.addSubview(fileNameLabel)
        msgContentView.addSubview(fileSizeLabel)

        stateLabel.snp.makeConstraints { make in
            make.bottom.equalTo(self.msgContentView.snp.bottom)
            make.right.equalTo(self.msgContentView.snp.left).offset(-20)
        }
        
        fileIconView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.bottom.equalTo(0)
            make.left.equalTo(0)
            make.right.equalTo(-MsgCellLayoutAdapterConfig.share.msgContentMaxWidth() - 50 - 0)
            make.width.height.equalTo(50)
        }
        
        fileNameLabel.snp.makeConstraints { make in
            make.left.equalTo(fileIconView.snp.right).offset(8)
            make.right.equalTo(-8)
            make.centerY.equalTo(self.fileIconView)
        }

        fileSizeLabel.snp.makeConstraints { make in
            make.left.equalTo(fileIconView.snp.right).offset(8)
            make.right.equalTo(-8)
            make.top.equalTo(self.fileNameLabel).offset(4)
        }
        
        fileNameLabel.setContentCompressionResistancePriority(.fittingSizeLevel, for: .horizontal)
        fileNameLabel.font = UIFont.systemFont(ofSize: 16);

        fileSizeLabel.setContentCompressionResistancePriority(.fittingSizeLevel, for: .horizontal)
        fileSizeLabel.font = UIFont.systemFont(ofSize: 13);

    }
    
    override func resetSubViewsLayout(showName: Bool, showHead: Bool) {
        super.resetSubViewsLayout(showName: showName, showHead: showHead)
        resetBubbleleView(aboveView: msgContentView)

    }
    
    override func bindFromModel(_ model: MsgCellBaseModel) {
        super.bindFromModel(model)
        
        let body = model.message.body as! EMFileMessageBody
        self.fileNameLabel.text = body.displayName
        self.fileSizeLabel.text = "\(body.fileLength)字节"
    }

    
    
    
    
    
    
    
    
    
    
    
    
}
